import { Enemy } from "./enemy.js";
import {Hero} from "./hero.js";
export class Manager{
    constructor(){
        this.init();
        this.role  = new Hero(70,80,300,300,this.fly1,this.boom);
        this.enemy = [{
            w:34,
            h:23,
            hp:1,
            fly:['./img/enemy1_fly_1.png'],
            boom:[
                './img/enemy1_blowup_1.png',
                './img/enemy1_blowup_2.png',
                './img/enemy1_blowup_3.png',
                './img/enemy1_blowup_4.png'
            ]
        },{
            w:92,
            h:120,
            hp:3,
            fly:[ './img/enemy2_fly_1.png'],
            boom:[
                './img/enemy2_blowup_1.png',
                './img/enemy2_blowup_2.png',
                './img/enemy2_blowup_3.png',
                './img/enemy2_blowup_4.png',
                './img/enemy2_blowup_5.png',
                './img/enemy2_blowup_6.png',
            ]
        },{
            w:46,
            h:64,
            hp:2,
            fly:['./img/enemy3_fly_1.png'],
            boom:[
                './img/enemy3_blowup_1.png',
                './img/enemy3_blowup_2.png',
                './img/enemy3_blowup_3.png',
                './img/enemy3_blowup_4.png'
            ]
        }];
        this.createEnemy();
        $('.gameOver div:nth-child(3)').click(()=>{
            location = location;
            $('.gameOver').css('display', 'none')
        })
    }
    //初始化宽高
    res(){
        $('.gameMain').css({
            width:`${$(window).innerWidth()}px`,
            height:`${$(window).innerHeight()}px`,
        })
    }
    
    static allEnemy = [];
    createEnemy(){
        let {floor,random} = Math;
        let _this = this;
       
        setInterval(() => {
            
            let enemy = [floor(random()*3)+3,floor(random()*3)+3,floor(random()*3)+3];
            // 三种飞机
            for (let i = 0; i < enemy.length; i++) {
                // 遍历其中一种飞机的数量
                for (let j = 0; j < enemy[i]; j++) {
                    //给每个飞机添加属性
                    let {w,h,fly,boom,hp} = _this.enemy[i];
                    let x = floor(random()*$(window).innerWidth())
                    let y = floor(random()*-2000);
                    let e = new Enemy(w,h,x,y,fly,boom,2,hp);
                    //添加入敌人的数组中
                    Manager.allEnemy.push(e);
                }
            }
        }, 5000);
    }

    init(){
        this.res();
        $(window).resize(()=>{
            this.res();
        })
        let bg_y = 0;
        setInterval(() => {
            bg_y += 4;
            if(bg_y >= 568){
                bg_y = 0;
            }
            $('.gameMain').css('backgroundPosition',`0 ${bg_y}px`);
        }, 1000/60);
        //初始化数据
        this.fly1 = ['./img/hero_fly_1.png','./img/hero_fly_2.png'];
        this.boom = [
            './img/hero_blowup_1.png',
            './img/hero_blowup_2.png',
            './img/hero_blowup_3.png',
            './img/hero_blowup_4.png',
        ]
        
    }

    
}